package com.xhl.noval.backend.controller;

import com.xhl.noval.api.core.entity.ApiResult;
import com.xhl.noval.api.service.NovelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author xionghl
 * @Description: 小说爬虫
 * @date 2022/4/16 17:24
 */
@RestController
@Api(tags = "小说爬虫")
@Slf4j
@RequestMapping("/crawler/novel")
public class NovelController {
    @Resource
    private NovelService novelService;

    @PostMapping("resolveSingleNovel")
    @ApiOperation("解析单本小说")
    public ApiResult<String> resolveSingleNovel(String url) throws IOException {
        return this.novelService.resolveSingleNovel(url);
    }

    @PostMapping("resolveSingleNovelContent")
    @ApiOperation("解析某网址的所有小说")
    public ApiResult<String> resolveSingleNovelContent() throws IOException {
       return ApiResult.success(this.novelService.resolveWebsiteNovel());
    }
}
